package com.itopener.elasticjob.spring.boot.autoconfigure;

import java.util.HashMap;
import java.util.Map;

import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties(prefix="spring.elasticjob")
public class ElasticJobProperties {
	
	private Zookeeper zk = new Zookeeper();
	
	private Map<String, JobProps> simpleJobs = new HashMap<String, JobProps>();
	
	private Map<String, JobProps> dataflowJobs = new HashMap<String, JobProps>();
	
	public static class JobProps {
		/** 任务执行时间cron表达式*/
		private String cron;
		
		/** 任务分片总数*/
		private int shardingTotalCount;
		
		/** 分片序列号/参数对照表*/
		private String shardingItemParameters;

		public String getCron() {
			return cron;
		}

		public void setCron(String cron) {
			this.cron = cron;
		}

		public int getShardingTotalCount() {
			return shardingTotalCount;
		}

		public void setShardingTotalCount(int shardingTotalCount) {
			this.shardingTotalCount = shardingTotalCount;
		}

		public String getShardingItemParameters() {
			return shardingItemParameters;
		}

		public void setShardingItemParameters(String shardingItemParameters) {
			this.shardingItemParameters = shardingItemParameters;
		}
		
	}
	
	class Zookeeper {
		/**
	     * 连接Zookeeper服务器的列表.
	     * 包括IP地址和端口号.
	     * 多个地址用逗号分隔.
	     * 如: host1:2181,host2:2181
	     */
	    private String serverLists = "127.0.0.1:2182";
	    
	    /**
	     * 命名空间.
	     */
	    private String namespace = "elastic-job-zk-namespace";
	    
	    /**
	     * 等待重试的间隔时间的初始值.
	     * 单位毫秒.
	     */
	    private int baseSleepTimeMilliseconds = 1000;
	    
	    /**
	     * 等待重试的间隔时间的最大值.
	     * 单位毫秒.
	     */
	    private int maxSleepTimeMilliseconds = 3000;
	    
	    /**
	     * 最大重试次数.
	     */
	    private int maxRetries = 3;
	    
	    /**
	     * 会话超时时间.
	     * 单位毫秒.
	     */
	    private int sessionTimeoutMilliseconds;
	    
	    /**
	     * 连接超时时间.
	     * 单位毫秒.
	     */
	    private int connectionTimeoutMilliseconds;
	    
	    /**
	     * 连接Zookeeper的权限令牌.
	     * 缺省为不需要权限验证.
	     */
	    private String digest;

		public String getServerLists() {
			return serverLists;
		}

		public void setServerLists(String serverLists) {
			this.serverLists = serverLists;
		}

		public String getNamespace() {
			return namespace;
		}

		public void setNamespace(String namespace) {
			this.namespace = namespace;
		}

		public int getBaseSleepTimeMilliseconds() {
			return baseSleepTimeMilliseconds;
		}

		public void setBaseSleepTimeMilliseconds(int baseSleepTimeMilliseconds) {
			this.baseSleepTimeMilliseconds = baseSleepTimeMilliseconds;
		}

		public int getMaxSleepTimeMilliseconds() {
			return maxSleepTimeMilliseconds;
		}

		public void setMaxSleepTimeMilliseconds(int maxSleepTimeMilliseconds) {
			this.maxSleepTimeMilliseconds = maxSleepTimeMilliseconds;
		}

		public int getMaxRetries() {
			return maxRetries;
		}

		public void setMaxRetries(int maxRetries) {
			this.maxRetries = maxRetries;
		}

		public int getSessionTimeoutMilliseconds() {
			return sessionTimeoutMilliseconds;
		}

		public void setSessionTimeoutMilliseconds(int sessionTimeoutMilliseconds) {
			this.sessionTimeoutMilliseconds = sessionTimeoutMilliseconds;
		}

		public int getConnectionTimeoutMilliseconds() {
			return connectionTimeoutMilliseconds;
		}

		public void setConnectionTimeoutMilliseconds(int connectionTimeoutMilliseconds) {
			this.connectionTimeoutMilliseconds = connectionTimeoutMilliseconds;
		}

		public String getDigest() {
			return digest;
		}

		public void setDigest(String digest) {
			this.digest = digest;
		}
	}

	public Zookeeper getZk() {
		return zk;
	}

	public void setZk(Zookeeper zk) {
		this.zk = zk;
	}

	public Map<String, JobProps> getSimpleJobs() {
		return simpleJobs;
	}

	public void setSimpleJobs(Map<String, JobProps> simpleJobs) {
		this.simpleJobs = simpleJobs;
	}

	public Map<String, JobProps> getDataflowJobs() {
		return dataflowJobs;
	}

	public void setDataflowJobs(Map<String, JobProps> dataflowJobs) {
		this.dataflowJobs = dataflowJobs;
	}

}
